﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using ChanExt;
using C.Unite;
using C.Entities;
using MySoft.Data;
namespace ArtLand.OA.Project.SystemMgr
{
    public partial class SysUserGroup : CommonPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //ChanExt.WindowField windowField1 = Grid1.FindColumn("myWindowField") as ChanExt.WindowField;
                //windowField1.DataIFrameUrlFormatString = "grid_iframe_window.aspx?id={0}&page={1}&param1=<script>" + TextBox1.GetValueReference() + "</script>";


                //btnDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("至少选择一项！");
                btnNew.OnClientClick = Window1.GetShowReference("SysUserGroupChange.aspx", "新增用户组");

                BindGrid();
            }
        }

        #region BindGrid

        private void BindGrid()
        {
            // 1.设置总项数
            Grid1.RecordCount = TbsDbSession.Default.From<Sys_UserGroup>().Count();

            List<Sys_UserGroup> items = TbsDbSession.Default.From<Sys_UserGroup>().OrderBy(Sys_UserGroup._.Orderid.Asc).ToList();

            // 3.绑定到Grid
            Grid1.DataSource = items;
            Grid1.DataBind();
        }


        protected string GetEditUrl(object id)
        {
            return "javascript:" + Window1.GetShowReference("SysModelMgrChange.aspx?id=" + id);
        }

        protected void Grid1_PageIndexChange(object sender, ChanExt.GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            BindGrid();
        }


        #endregion

        #region Events

        //protected void btnDelete_Click(object sender, EventArgs e)
        //{
        //    int returnvalue = 0;
        //    bool bl = true;
        //    foreach (int row in Grid1.SelectedRowIndexArray)
        //    {
        //        int id=int.Parse(Grid1.DataKeys[row][0].ToString());
        //        int c=TbsDbSession.Default.From<Sys_Modules>().Where(Sys_Modules._.Topmid==id).Count();
        //        if (c == 0)
        //        {
        //            returnvalue += TbsDbSession.Default.Delete<Sys_Modules>(Sys_Modules._.Mid == id);
        //        }
        //        else
        //        {
        //            bl = false;
        //        }

        //    }
        //    if (returnvalue > 0)
        //    {
        //        if (bl == false)
        //        {
        //            Alert.ShowInTop("删除成功！但有些模块还存在子模块！");
        //            BindGrid();
        //        }
        //        else
        //        {
        //            Alert.ShowInTop("删除成功！");
        //            BindGrid();
        //        }
        //    }

        //}


        #endregion
        protected void Grid1_RowDataBound(object sender, ChanExt.GridRowEventArgs e)
        {

        }

        protected void Grid1_RowCommand(object sender, ChanExt.GridCommandEventArgs e)
        {
            int id = int.Parse(Grid1.DataKeys[e.RowIndex][0].ToString());
            if (e.CommandName == "Del")
            {
                TbsDbSession.Default.Delete<Sys_UserGroup>(Sys_UserGroup._.Ugid == id);
                Alert.ShowInTop("删除成功！");
                BindGrid();

            }
        }
    }
}